package com.my.commonlibrary.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.my.commonlibrary.R;
import com.my.commonlibrary.widget.pageindicator.CirclePageIndicator;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Author : Cooper
 * Time : 2016/10/19  14:37
 * Description : 软件导航Activity
 */

public class GuideActivity extends Activity {

    @Bind(R.id.view_pager)
    ViewPager viewPager;
    @Bind(R.id.indicator)
    CirclePageIndicator indicator;

    private int[] images = {R.drawable.guide_1,R.drawable.guide_2,R.drawable.guide_3,R.drawable.guide_4,R.drawable.guide_5};
    private List<ImageView> imageViewList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.aty_guide_layout);
        ButterKnife.bind(this);
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        getWindow().setFlags(flag,flag);
        initView();
    }

    private void initView() {
        for (int res : images) {
            ImageView imageView = new ImageView(this);
            imageView.setBackgroundResource(res);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageViewList.add(imageView);
        }
        viewPager.setAdapter(new GuideAdapter(imageViewList));
        indicator.setRadius(5);
        indicator.setViewPager(viewPager);
    }

    class GuideAdapter extends PagerAdapter{

        private List<ImageView> list;

        public GuideAdapter(List<ImageView> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = list.get(position);
            container.addView(imageView);
            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View)object);
        }
    }
}
